﻿using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using QuanLyKhachSan;
using System.Data;
using System.Data.SqlClient;
using QuanLyKhachSan.DTO;

namespace UnitTest
{
    public  class clsTestLoaiKhachHang:clsTest 
    {
        public LoaiKhachHangDTO loaiKHdto;

        public bool Assert_Clauses(DataTable expected, LoaiKhachHangDTO actual)
        {
            if (expected.Rows.Count > 0)
            {
                DataRow dr = expected.Rows[0];
                Assert.AreEqual((int)dr["maLoaiKH"], actual.MaLoaiKH, "I hope the maLoaiKhachHang is the same");
                Assert.AreEqual(dr["tenLoai"], actual.TenLoai, "I hope the tenLoaiKhachHang is the same");
                Assert.AreEqual(float.Parse(dr["heSoNhan"].ToString()),actual.HeSoNhan,"I hope the heSoNhan is the same");
                Assert.AreEqual((int)dr["danhDau"], actual.DanhDau, "I hope the danhDau is the same");

                return true;
            }
            return false;
        }

        [Test]
        public void TestInsert()
        {
            LoaiKhachHangDTO loaiKH = new LoaiKhachHangDTO();
            loaiKH.TenLoai = "Loại Khách Hàng Test2";
            loaiKH.HeSoNhan = 3;

            bool kq = LoaiKhachHangDAO.Insert(loaiKH);

            Dictionary<string, object> para = new Dictionary<string, object>();
            para.Add("tenLoai", loaiKH.TenLoai);
            para.Add("heSoNhan", loaiKH.HeSoNhan);

            expectedData = select_DataTable("LoaiKhachHang", para);
            if (expectedData.Rows.Count == 0)
            {
                Assert.IsFalse(kq);
            }
            else
            {
                Assert.GreaterOrEqual(expectedData.Rows.Count, 1, "Cần Insert xuống CSDL");
                Assert.IsTrue(kq);
                Assert.AreEqual(expectedData.Rows[0]["tenLoai"], loaiKH.TenLoai, "tenLoaiKhachHang not the same");
                Assert.AreEqual(float.Parse(expectedData.Rows[0]["heSoNhan"].ToString()), loaiKH.HeSoNhan, "heSoNhan not the same");

            }
        }

        [Test]
        public void TestUpdateLoaiKhachHang()
        {
            LoaiKhachHangDTO loaiKH = new LoaiKhachHangDTO();
            loaiKH.MaLoaiKH = 1;
            loaiKH.TenLoai = "A1 Test";
            loaiKH.HeSoNhan = float.Parse("2");
            loaiKH.DanhDau = 0;

            bool kq = LoaiKhachHangDAO.Update(loaiKH);

            Dictionary<string, object> para = new Dictionary<string, object>();
            para.Add("maLoaiKH", loaiKH.MaLoaiKH);

            expectedData = select_DataTable("LoaiKhachHang", para);
            if (expectedData.Rows.Count == 0)
            {
                Assert.IsFalse(kq);
            }
            else
            {
                Assert_Clauses(expectedData, loaiKH);
                Assert.IsTrue(kq);
            }
        }
    }
}
